//
//  NSString+Common.m
//  EverVCiOSClient
//
//  Created by evervc on 15/12/10.
//  Copyright © 2015年 EverVC. All rights reserved.
//

#import "NSObject+Common.h"

@implementation NSObject (Common)



- (BOOL)isHaveStr
{
    if (self == nil || [self isEqual:[NSNull null]])
    {
        return NO;
    } else if ([self isEqual:@""] == YES || [self isKindOfClass:[NSString class]] == YES) {
        NSString *str = (NSString *)self;
        if ([str isEqualToString:@""] == YES) {
            return NO;
        } else {
            return YES;
        }
        
    } else if ([self respondsToSelector:@selector(length)] == YES) {
        NSString *str = (NSString *)self;
        if (str.length > 0) {
            return YES;
        }
        return NO;
    } else {
        return YES;
    }
}

- (NSString *)safeString {
    
    if ([self isHaveStr] == YES) {
        return [NSString stringWithFormat:@"%@",self];
    } else {
        return @"";
    }
}


+ (NSString *)safeString:(NSString *)targetStr {
    return [self kk_safeString:targetStr];
}

+ (NSString *)safeNumber:(NSString *)targetStr {
    if ([targetStr isHaveStr] == YES) {
        return [NSString stringWithFormat:@"%@",targetStr];
    } else {
        return @"0";
    }
}

+ (NSString *)kk_safeString:(NSString *)targetStr {
    if ([targetStr isHaveStr] == YES) {
        return [NSString stringWithFormat:@"%@",targetStr];
    } else {
        return @"";
    }
}


@end



@implementation NSString (IntegerToString)

+ (NSString *)stringWithInteger:(NSInteger)num {
    return [self kk_stringWithInteger:num];
}
+ (NSString *)kk_stringWithInteger:(NSInteger)num {
    return [NSString stringWithFormat:@"%ld", num];
}
+ (NSString *)kk_stringWithFloat:(CGFloat)flt {
    return [[NSNumber numberWithFloat:flt] stringValue];
}
+ (NSString *)kk_stringWithDouble:(double)d {
    
    NSString *dStr = [NSString stringWithFormat:@"%lf", d];
    NSDecimalNumber *num = [NSDecimalNumber decimalNumberWithString:dStr];
    return [num stringValue];
    
//    return [[NSNumber numberWithDouble:d] stringValue];
}

@end
